package org.umss.fixture.services;

import java.io.IOException;
import java.net.ConnectException;
import java.net.MalformedURLException;
import java.net.UnknownHostException;

public class ConnectionExceptionMessageCreator {
    public String getMessage(int code) {
	String lastException;
	switch (code) {
	case 204:
	    return "The server response does not contain any data";
	case 404:
	    lastException = "The requested resource could not be found";
	    break;
	case 403:
	    lastException = "Forbidden connection. The server is refusing to respond.";
	    break;
	case 405:
	    lastException = "Method Not Allowed.";
	    break;
	default:
	    lastException = "There was an error:" + code;
	}
	return lastException;
    }

    public String getMessage(Exception e) {
	if (e instanceof UnknownHostException) {
	    return "The host: '" + e.getMessage() + "' is unknown.";
	}

	if (e instanceof ConnectException) {
	    return "Connection Error: " + e.getMessage();
	}

	if (e instanceof IOException) {
	    return e.getMessage();
	}

	if (e instanceof MalformedURLException) {
	    return e.getMessage();
	}
	
	return e.getMessage();
    }
}
